package com.xiongtian.springframework.aop.framework;

import com.xiongtian.springframework.aop.AdvisedSupport;

/**
 * @Author: xiongtian
 * @CreateTime: 2025-04-18  16:16
 * @Version: 1.0
 * @Description: 代理工厂
 */

public class ProxyFactory {

    /**
     * AdvisedSupport 中包含了目标对象，拦截器，拦截器链等信息
     */
    private AdvisedSupport advisedSupport;

    public ProxyFactory(AdvisedSupport advisedSupport) {
        this.advisedSupport = advisedSupport;
    }

    public Object getProxy(){
        return createAopProxy().getProxy();
    }

    private AopProxy createAopProxy() {
        if (advisedSupport.isProxyTargetClass()) {
            return new Cglib2AopProxy(advisedSupport);
        }else {
            return new JdkDynamicAopProxy(advisedSupport);
        }
    }

}
